index.tsx 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use client";
  2. import { ChangeEvent, FC, PropsWithChildren, useMemo, useState } from "react";
  3. import clsx from "clsx";
  4. import Link from "next/link";
  5. import ButtonOwn from "@/components/ButtonOwn";
  6. import "./style.scss";
  7. /**
  8. * @description 登录注册From表单
  9. * @param {string} type 使用类型
  10. * @param {(params: any) => void} callbackFun 回调方法
  11. */
  12. export interface FromComProps {
  13. type?: string;
  14. text?: string;
  15. callbackFun?: (params: any) => void;
  16. }
  17. const FromCom: FC<PropsWithChildren<FromComProps>> = ({type = 'login', callbackFun}) => {
  18. let [pwdVisible, setPwdVisible] = useState(false)
  19. const spanClassName = clsx("iconfont", {
  20. "icon-kejian": pwdVisible,
  21. "icon-bukejian": !pwdVisible,
  22. });
  23. let [fromParam, setFromParam] = useState({
  24. userPhone: '',
  25. pwd: ''
  26. })
  27. const activeCls = useMemo(() => {
  28. let { userPhone, pwd } = fromParam
  29. if (userPhone && userPhone.length==11 && pwd && pwd.length>6) {
  30. return true
  31. }
  32. return false
  33. }, [fromParam]);
  34. const setInputVal = (e: ChangeEvent<HTMLInputElement>, propsName: string) => {
  35. setFromParam({
  36. ...fromParam,
  37. [propsName]: e.target.value
  38. })
  39. }
  40. const verifyPwd = (e: any) => {
  41. let pwd = e.target.value || '';
  42. pwd.replaceAll(/[^a-zA-Z0-9_-]/g, '')
  43. setFromParam({ ...fromParam, pwd })
  44. console.log('fromParam', fromParam.pwd)
  45. }
  46. const submitRequest = () => {
  47. activeCls && callbackFun!(fromParam)
  48. }
  49. return (
  50. <div className="FromCom">
  51. <div className="phoneInput">
  52. <span className="after">+55</span>
  53. <input type="tel" value={fromParam.userPhone} onChange={(e) => setInputVal(e, 'userPhone') } placeholder="Número de Celular" maxLength={11} />
  54. </div>
  55. <div className="passwordInput">
  56. <input type={pwdVisible?'text':'password'} value={fromParam.pwd} onChange={(e) => setInputVal(e, 'pwd') } onInput={verifyPwd} placeholder="Senha" maxLength={12}/>
  57. <span className={spanClassName} onClick={() => setPwdVisible(!pwdVisible)}></span>
  58. </div>
  59. <div className="btnContent">
  60. <div className="tips"> O número de telefone não existe. </div>
  61. <ButtonOwn active={activeCls} callbackFun={submitRequest}>{type == 'login'? 'Login' : 'Criar conta'}</ButtonOwn>
  62. </div>
  63. <div className="link">
  64. {
  65. type == 'login' ? (
  66. <>
  67. <Link href="/br/resetPhone">Esqueci minha senha?</Link>
  68. <Link href="/br/register">Criar Conta Nova</Link>
  69. </>
  70. ) : <Link href="/br/login" className="active" replace>Já tem uma conta? Log in</Link>
  71. }
  72. </div>
  73. </div>
  74. );
  75. };
  76. export default FromCom;